package com.scope.imageFilters;

/**
 * Created by Samrith on 12/10/13.
 */
public class MorphoParam {
    public MorphoParam(int matrixPercentage) {
    	this(matrixPercentage, 0);
    }

    public MorphoParam(int matrixPercentage, int iteration) {
    	if (matrixPercentage > 100) {
    		mMatPct = 100;
    	} else if (matrixPercentage < -100) {
    		mMatPct = -100;
    	} else {
    		mMatPct = matrixPercentage;
    	}
        mIteration = iteration;
    }

    private int mMatPct;
    public int getMatrixPercentage() {
        return mMatPct;
    }

    private int mIteration;
    public int getIteration() {
        return mIteration;
    }

    @Override
    public String toString() {
        return Integer.toString(mMatPct) + QUERY + Integer.toString(mIteration);
    }

    public static MorphoParam fromString(String str) {
        String[] parts = str.split(MorphoParam.QUERY);
        if (parts.length == 1) {
        	return new MorphoParam(
        			Integer.parseInt(parts[0]),
        			0
        	);
        } else if (parts.length == 2) {
            return new MorphoParam(
                    Integer.parseInt(parts[0]),
                    Integer.parseInt(parts[1])
            );
        } else {
            throw new IllegalArgumentException(str);
        }
    }

    public final static String QUERY = ";;";
}
